﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using JupiterLibrary;

namespace KinnectInput.KinectVideo
{
    public class VideoPlayerControlBar
    {
        public VideoPlayerButton PlayBtn { get; private set; }
        public VideoPlayerButton StopBtn { get; private set; }
        public VideoPlayerButton PauseBtn { get; private set; }
        Rectangle VideoSize;
        Rectangle BarSize;
        Sprite DisplayBar;
        
        public float Opacity;
        public VideoPlayerControlBar(Rectangle VideoSize, bool horizontal)
        {
            this.VideoSize = VideoSize;
            Opacity = 1;
            DisplayBar = new Sprite();
            DisplayBar.SetColor(new Color(0, 0, 0, 0.5f));
            if (horizontal)
            {
                BarSize = new Rectangle(VideoSize.X, VideoSize.Y + VideoSize.Height - VideoSize.Height / 10, VideoSize.Width, VideoSize.Height / 5);
            }
            else
            {
                BarSize = new Rectangle(VideoSize.X - VideoSize.X / 3, VideoSize.Y, VideoSize.Width / 6, VideoSize.Height);
            }
            DisplayBar.SetRectangle(BarSize);
            DisplayBar.Update();
            int buttonSize;
            if (BarSize.Height > BarSize.Width)
            {
                buttonSize = BarSize.Width;
                PlayBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/play"), new Rectangle(BarSize.X,  (int)(BarSize.Center.Y - (buttonSize * 1.6)), buttonSize, buttonSize));
                PauseBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/Pause"), new Rectangle(BarSize.X, (int)(BarSize.Center.Y - (buttonSize * 0.5)), buttonSize, buttonSize));
                StopBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/stop"), new Rectangle(BarSize.X, (int)(BarSize.Center.Y + (buttonSize * 0.6)),  buttonSize, buttonSize));
                
            }
            else
            {
                buttonSize = BarSize.Height;
                PlayBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/play"), new Rectangle((int)(BarSize.Center.X - (buttonSize * 1.7)), BarSize.Y, buttonSize, buttonSize));
                StopBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/stop"), new Rectangle((int)(BarSize.Center.X + (buttonSize * 0.5)), BarSize.Y, buttonSize, buttonSize));
                PauseBtn = new VideoPlayerButton(Jupiter.Content.Load<Texture2D>("Video/Pause"), new Rectangle((int)(BarSize.Center.X - (buttonSize * 0.6)), BarSize.Y, buttonSize, buttonSize));
            }
            
        }
        public void Update()
        {
            if (this.Opacity < 1f)
            {
                DisplayBar.SetAlpha(this.Opacity);
            }
            if (PlayBtn.PlayerButtonState == VideoPlayerButtonState.Selected)
            {
                PauseBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
                StopBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
            }
            else if (PauseBtn.PlayerButtonState == VideoPlayerButtonState.Selected)
            {
                PlayBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
                StopBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
            }
            else if (StopBtn.PlayerButtonState == VideoPlayerButtonState.Selected)
            {
                PlayBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
                PauseBtn.PlayerButtonState = VideoPlayerButtonState.InActive;
            }

            PlayBtn.Opacity *= this.Opacity;
            PauseBtn.Opacity *= this.Opacity;
            StopBtn.Opacity *= this.Opacity;

            PlayBtn.Update();
            PauseBtn.Update();
            StopBtn.Update();
            DisplayBar.Update();
        }
        public void Draw()
        {
            DisplayBar.Draw();
            PlayBtn.Draw();
            PauseBtn.Draw();
            StopBtn.Draw();
        }
        
    }
}
